package linkedlist;

import java.util.LinkedList;
import java.util.ListIterator;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: YKH
 * Date: 2022-05-10
 * Time: 8:58
 * author:Test02
 */
public class Test02 {
    //LinkedList 的使用
    public static void main(String[] args) {
        LinkedList <Integer> list1 = new LinkedList();
        LinkedList <Integer> list2 = new LinkedList();
        //添加到尾部
        list1.add(10);
        list1.add(100);
        list1.add(200);
        list1.add(300);
        list2.add(1);
        list2.add(2);
        list2.add(3);
        //添加集合
        list2.addAll(list1);

        //foreach遍历
        for (Integer x:list2) {
            System.out.print(x + " ");
        }
        System.out.println();
        // 使用迭代器遍历---正向遍历
        ListIterator<Integer> it = list2.listIterator();
        while(it.hasNext()){
        System.out.print(it.next()+ " ");
        }
        System.out.println();

        // 使用反向迭代器---反向遍历
        ListIterator<Integer> rit = list2.listIterator(list2.size());
        while (rit.hasPrevious()){
        System.out.print(rit.previous() +" ");
        }
        System.out.println();

    }
}
